package util;

import java.util.*;

import antlr.collections.AST;

import FlowGraph.FlowGraphNode;

//////////////////////////////////////////////////////////////////////////
//// Line
/**
@author Ivan Jeukens
@version v 0.1 07/02/2002
*/
public class Line {

    public Line(String text, AST node, FlowGraphNode fgnode, int spaces, 
            int ident, int number) {
        _text = text;
        _node = node;
        _fgnode = fgnode;
        _spaces = spaces;
        _ident = ident;
        _number = number;
    }

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void setNumber(int value) {
        _number = value;
    }
   
    public int getNumber() {
        return _number;
    }

    public int getSpaces() {
        return _spaces;
    }    

    public void setText(String text) {
        _text = text;
    }
    
    public String getText() {
        return _text;   
    }
    
    public AST getNode() {
        return _node;
    }
    
    public int getIdent() {
        return _ident;
    }
    
    public void setIdent(int value) {
        _ident = value;
    }
    
    public FlowGraphNode getFlowGraphNode() {
        return _fgnode;
    }
    
    public String exportXML(HashMap nodeIndex) {
        StringBuffer buf = new StringBuffer("<Line ASTNodeIndex=\"");        
        if(_node == null) {
            buf.append("-1");
        }
        else {            
            Integer i = (Integer) nodeIndex.get(_node);
            buf.append(i.intValue()); 
        }
        buf.append("\" fgnode=\"");
        if(_fgnode == null) {
            buf.append("-1");
        }
        else {
            buf.append(_fgnode.getUniqueNum());
        }
        buf.append("\" spaces=\"" + _spaces + "\" ident=\"" + _ident + 
            "\" number=\"" + _number + "\">\n");

        buf.append("<codeText>\n");
        buf.append("  <![CDATA[" + _text + "]]>\n");
        buf.append("</codeText>\n");
        buf.append("</Line>\n");

        return buf.toString();
    }

    public String toString() {
        return _text;
    }

    public Line duplicate() {
        Line ret = new Line(_text, _node, _fgnode, _spaces, _ident,
            _number);
        return ret;
    }

    ///////////////////////////////////////////////////////////////////
    ////                        private methods                    ////

    ///////////////////////////////////////////////////////////////////
    ////                      private variables                    ////

    private int _spaces;
    private String _text;
    private AST _node;
    private int _ident;
    private int _number;
    private FlowGraphNode _fgnode;
}
